package com.example.demo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class IndexFilter implements WebMvcConfigurer {

  @Bean
  public LoginHandlerInterceptor getLoginHandler(){
    return new LoginHandlerInterceptor();
  }

  @Override
  public void addInterceptors(InterceptorRegistry registry){
    //配置需要拦截的请求，不需要拦截的请求：登录页面和静态页面
    registry.addInterceptor(getLoginHandler())
    .addPathPatterns("/**")
    .excludePathPatterns("/login")
    .excludePathPatterns("/assets/**");
  }

}
